//--------------------cookie相关方法-----------------------
//设置cookie，不设置days默认为30天
function setCookie(keys,vals,days){
	var oDate = new Date();
	var t = Number(days) || 30;
	oDate.setDate(oDate.getDate() + t);
	document.cookie = keys + '=' + encodeURI(vals) + ';expires=' + oDate.toGMTString(); 
}
//获取cookie
function getCookie(keys){
	var arr = document.cookie.split('; ');
	for(var i=0;i<arr.length;i++){
		if(arr[i].split('=')[0] === keys){
			return decodeURI(arr[i].split('=')[1]);
		}
	}
}
//删除一个cookie
function removeCookie(keys){
	setCookie(keys,'',-1);
}
//删除所有cookie
function clearCookie(){
	var arr = document.cookie.split('; ');    		
	for(var i=0;i<arr.length;i++){    			
		removeCookie(arr[i].split('=')[0],'',-1);
	}
}

module.exports = {
    setCookie,    
    getCookie,
    removeCookie,
    clearCookie
}